package com.SunSoft.PhoneRemoteControl;

import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Environment;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public final class fy
{
  private static String e = "/data/data/com.SunSoft.PhoneRemoteControl/databases/temp_save.dat";
  private Runnable A = new ga(???);
  private Context a;
  private String b = "";
  private String c = "http://www.tasogo.com/UPdate_value/T800.apk";
  private String d = "http://www.tasogo.com/UPdate_value/tsg_temp.rar";
  private Dialog f;
  private Dialog g;
  private Dialog h;
  private String i = Environment.getExternalStorageDirectory() + "/temp/";
  private String j = ???.i + "T800.apk";
  private String k = ???.i + "tsg_data.rar";
  private ProgressBar l;
  private int m;
  private Thread n;
  private boolean o = false;
  private String p = "1.5";
  private String q;
  private String r;
  private String s;
  private String t;
  private String u;
  private dh v;
  private int w = 0;
  private String x = ???.q;
  private String y = "";
  private Handler z = new fz(???);

  public fy(Context paramContext)
  {
    this.a = paramContext;
  }

  private boolean d()
  {
    File localFile = new File(this.k);
    try
    {
      FileInputStream localFileInputStream = new FileInputStream(localFile);
      FileOutputStream localFileOutputStream = new FileOutputStream(e);
      byte[] arrayOfByte = new byte[1024];
      int i1 = localFileInputStream.read(arrayOfByte);
      if (i1 <= 0)
      {
        localFileOutputStream.flush();
        localFileOutputStream.close();
        localFileInputStream.close();
        if (!(localFile.exists()))
          break label106;
        localFile.delete();
        break label106:
      }
      localFileOutputStream.write(arrayOfByte, 0, i1);
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      localFileNotFoundException.printStackTrace();
      return false;
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
      return false;
    }
    label106: return true;
  }

  private void e()
  {
    AlertDialog.Builder localBuilder = new AlertDialog.Builder(this.a);
    if (this.w == 2)
    {
      localBuilder.setTitle(this.a.getString(2131099664));
      localBuilder.setMessage(this.b);
      if (Environment.getExternalStorageState().equals("mounted"))
        break label109;
      localBuilder.setNegativeButton(this.a.getString(2131099655), new ge(this));
    }
    while (true)
    {
      while (true)
      {
        this.f = localBuilder.create();
        this.f.show();
        return;
        localBuilder.setTitle(this.a.getString(2131099662));
      }
      label109: localBuilder.setNeutralButton(this.a.getString(2131099658), new gf(this));
      localBuilder.setNegativeButton(this.a.getString(2131099659), new gg(this));
    }
  }

  public final String a(int paramInt, String paramString)
  {
    Object localObject;
    this.w = paramInt;
    this.v = new dh(this.a);
    this.q = this.v.a("db_v");
    int i1 = 1;
    if (paramInt == 0)
      i1 = 0;
    paramInt = i1;
    try
    {
      paramString = paramString.split("\\|");
      paramInt = i1;
      if (paramString.length > 6)
      {
        paramInt = i1;
        localObject = this.a.getPackageManager();
        label1157: label396: label1038: label671: label1079: label1098: label995: label1138: paramInt = i1;
      }
    }
    catch (java.lang.Exception paramString)
    {
      float f1;
      float f2;
      int i2;
      try
      {
        this.p = ((PackageManager)localObject).getPackageInfo(this.a.getPackageName(), 0).versionName;
        paramInt = i1;
        localObject = this.p.split("\\.");
        i2 = 0;
        f1 = 0.0F;
        paramInt = i1;
        if (i2 < localObject.length)
          break label995;
        f2 = 0.0F;
        paramInt = i1;
        localObject = paramString[0].split("\\.");
        i2 = 0;
        paramInt = i1;
        if (i2 < localObject.length)
          break label1038;
        if (f2 <= f1)
          break label1079;
        paramInt = i1;
        this.v.a("has_new_soft", "YES");
        i2 = i1;
        if (f2 > f1)
        {
          paramInt = i1;
          if (this.w != 0)
          {
            paramInt = i1;
            if (this.w != 1)
            {
              i2 = i1;
              paramInt = i1;
              if (this.w != 3)
                break label396;
            }
          }
          paramInt = i1;
          this.b = this.a.getString(2131099666) + paramString[0] + "\n" + this.a.getString(2131099668) + paramString[1] + "\n" + this.a.getString(2131099667) + paramString[2] + "\n";
          paramInt = i1;
          if (Environment.getExternalStorageState().equals("mounted"))
            break label1098;
          paramInt = i1;
          this.b += this.a.getString(2131099669);
          paramInt = i1;
          this.w = 1;
          paramInt = i1;
          e();
          i2 = 0;
        }
        paramInt = i2;
        this.x = paramString[6];
        paramInt = i2;
        int i5 = Integer.valueOf(this.q).intValue();
        paramInt = i2;
        int i6 = Integer.valueOf(this.x).intValue();
        if (i6 <= i5)
          break label1138;
        paramInt = i2;
        this.v.a("has_new_data", "YES");
        i1 = i2;
        if (i6 > i5)
        {
          paramInt = i2;
          if (this.w != 0)
          {
            paramInt = i2;
            if (this.w != 2)
            {
              i1 = i2;
              paramInt = i2;
              if (this.w != 3)
                break label671;
            }
          }
          paramInt = i2;
          this.b = this.a.getString(2131099666) + paramString[6] + "\n" + this.a.getString(2131099668) + paramString[7] + "\n" + this.a.getString(2131099667) + paramString[8] + "\n";
          paramInt = i2;
          if (Environment.getExternalStorageState().equals("mounted"))
            break label1157;
          paramInt = i2;
          this.b += this.a.getString(2131099669);
          paramInt = i2;
          this.w = 2;
          paramInt = i2;
          e();
          i1 = 0;
        }
        paramInt = i1;
        this.r = this.v.a("last_ad_time");
        i2 = i1;
        paramInt = i1;
        if (!(this.r.equals(paramString[3])))
        {
          i2 = i1;
          if (i1 != 0)
          {
            i2 = i1;
            paramInt = i1;
            if (!(paramString[3].equals("2014-03-16 09:21:15")))
            {
              paramInt = i1;
              this.s = paramString[3];
              paramInt = i1;
              this.t = paramString[4];
              paramInt = i1;
              this.u = paramString[5];
              paramInt = i1;
              paramString = new AlertDialog.Builder(this.a);
              paramInt = i1;
              paramString.setTitle(this.a.getString(2131099670));
              paramInt = i1;
              paramString.setMessage(this.t);
              paramInt = i1;
              paramString.setNeutralButton(this.a.getString(2131099655), new gb(this));
              paramInt = i1;
              if (this.u.startsWith("http"))
              {
                paramInt = i1;
                paramString.setPositiveButton(this.a.getString(2131099660), new gc(this));
              }
              paramInt = i1;
              paramString.setNegativeButton(this.a.getString(2131099661), new gd(this));
              paramInt = i1;
              this.h = paramString.create();
              paramInt = i1;
              this.h.show();
              i2 = 1;
            }
          }
        }
        paramInt = i2;
        paramString = this.a.getString(2131099674);
        paramInt = i2;
        if (paramInt != 0)
        {
          this.y = paramString;
          this.z.sendEmptyMessage(4);
        }
        return paramString;
      }
      catch (PackageManager.NameNotFoundException localNameNotFoundException)
      {
        while (true)
        {
          int i4;
          while (true)
          {
            while (true)
            {
              while (true)
              {
                while (true)
                {
                  int i3;
                  while (true)
                  {
                    while (true)
                    {
                      while (true)
                      {
                        paramInt = i1;
                        this.p = "1.0";
                      }
                      paramString = paramString;
                      paramString = this.a.getString(2131099675);
                    }
                    double d1 = f1;
                    paramInt = i1;
                    f1 = (float)(d1 + Float.valueOf(localNameNotFoundException[i2]).floatValue() / Math.pow(10.0D, i2));
                    i2 += 1;
                  }
                  paramInt = i1;
                  f2 = (float)(f2 + Float.valueOf(localNameNotFoundException[i3]).floatValue() / Math.pow(10.0D, i3));
                  i3 += 1;
                }
                paramInt = i1;
                this.v.a("has_new_soft", "NO");
              }
              paramInt = i1;
              this.b += this.a.getString(2131099671);
            }
            paramInt = i4;
            this.v.a("has_new_data", "NO");
          }
          paramInt = i4;
          this.b += this.a.getString(2131099673);
        }
        paramInt = i1;
        paramString = this.a.getString(2131099675);
        paramInt = i1;
      }
    }
  }

  protected final void a()
  {
    AlertDialog.Builder localBuilder = new AlertDialog.Builder(this.a);
    if (this.w == 2)
      localBuilder.setTitle(this.a.getString(2131099665));
    while (true)
    {
      View localView = LayoutInflater.from(this.a).inflate(2130903067, null);
      this.l = ((ProgressBar)localView.findViewById(2131165237));
      localBuilder.setView(localView);
      localBuilder.setNegativeButton(this.a.getString(2131099654), new gh(this));
      this.g = localBuilder.create();
      this.g.show();
      this.n = new Thread(this.A);
      this.n.start();
      return;
      localBuilder.setTitle(this.a.getString(2131099663));
    }
  }

  protected final void b()
  {
    File localFile = new File(this.j);
    if (!(localFile.exists()))
      return;
    Intent localIntent = new Intent("android.intent.action.VIEW");
    localIntent.setDataAndType(Uri.parse("file://" + localFile.toString()), "application/vnd.android.package-archive");
    this.a.startActivity(localIntent);
  }
}